﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MySSH.Common.Helper;
using NHibernate.Criterion;

namespace MySSH.Web.Controllers
{
    public class SysLogNetController : Controller
    {
        public IBLL.IBLLBase<Domain.Entities.SysLogNet> BLL { get; set; }
        //
        // GET: /SysLogNet/

        public ActionResult GetList()
        {
            List<ICriterion> icList = new List<ICriterion>();
            int totalCount = 0;

            string BeginDate = Request.Form["BeginDate"];
            string EndDate = Request.Form["EndDate"];
            if (!string.IsNullOrEmpty(BeginDate))
                icList.Add(Restrictions.Ge("LogTime", Convert.ToDateTime(BeginDate)));
            if (!string.IsNullOrEmpty(EndDate))
                icList.Add(Restrictions.Le("LogTime", Convert.ToDateTime(EndDate)));
            //icList.Add(Restrictions.Between("LogTime", Convert.ToDateTime(BeginDate), Convert.ToDateTime(EndDate)));

            string ActionType = Request.Form["ActionType"];
            if (!string.IsNullOrEmpty(ActionType))
                icList.Add(Restrictions.Eq("ActionType", ActionType));

            string LogLevel = Request.Form["LogLevel"];
            if (!string.IsNullOrEmpty(LogLevel))
                icList.Add(Restrictions.Eq("LogLevel", LogLevel));

            int limit = Convert.ToInt32(Request.Form["limit"]);
            int start = Convert.ToInt32(Request.Form["start"]);
            string sort = Request.Form["sort"];
            string dir = Request.Form["dir"];
         

     
  
    
            var list = this.BLL.GetListByPage(start, limit, sort, dir, out totalCount, icList).ToList();
            //var list = this.BLL.GetQueryByLinq().Where(p => p.LogTime >= BeginDate && p.LogTime <= EndDate).ToList();
            //string json = JSONHelper.ToJSON(list);
            //return this.Content(string.Format("{total:{0},success:true,data:{1}}}", list.Count, json));
            return Json(new { totalCount = totalCount, success = true, data = list });
        }
    }
}
